package com.msb.tank.utils;

import java.awt.*;
import java.awt.image.BufferedImage;

public class ImageUtil {
    /**
     * 图片选择角度
     *
     * @param bufferedImage 内存中的图片
     * @param degree        角度
     * @return 旋转后的图片
     */
    public static BufferedImage rotateImage(final BufferedImage bufferedImage, final int degree) {
        final int w = bufferedImage.getWidth();
        final int h = bufferedImage.getHeight();
        final int transparency = bufferedImage.getColorModel().getTransparency();
        BufferedImage img;
        Graphics2D graphics2D;

        img = new BufferedImage(w, h, transparency);
        graphics2D = img.createGraphics();
        graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                RenderingHints.VALUE_INTERPOLATION_BILINEAR);
        graphics2D.rotate(Math.toRadians(degree), w / 2, h / 2);
        graphics2D.drawImage(bufferedImage, 0, 0, null);
        graphics2D.dispose();
        return img;
    }
}
